package org.tjc.net.manager.config.json;

import org.tjc.net.manager.exception.ParseConfException;

public class ConfLoader {
    private Configuration conf;
    public ConfLoader(Configuration conf) {
        this.conf = conf;
    }

    public NgMainModule parse() {
        NgMainModule context = new NgMainModule();
        for (String key : conf.getKeys()) {
            if (!MetaNgCommand.contains(key)) {
                throw new ParseConfException("unexpect key: " + key);
            }
            MetaNgCommand subCmd = MetaNgCommand.get(key);
            if (subCmd.isModule()) {
                Configuration subConf = conf.getConfiguration(key);
                subCmd.invoke(context, subConf);
            } else if (subCmd.isCmd()) {
                Object value = conf.get(key);
                subCmd.invoke(context,key, value);
            }
        }
        return context;
    }
}
